home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / tutorials / geometer / message.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.6 KB  |  195 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. #include <gl.h>
  19. #include <device.h>
  20. #include <unistd.h>
  21. #include "showcaseui.h"
  22. #include "generic.h"
  23.  
  24. /* This file implements the message() command that is called in various
  25.  * places to present messages and to ask for confirmation.  It happens 
  26.  * to use the Showcase libui.  If you don't like this code, toss this
  27.  * file out, but provide a routine called message that does the same
  28.  * sorts of things this one does.
  29.  */
  30.  
  31. static Button *ybut = 0, *nbut = 0, *cbut = 0;
  32. static long xmin, xmax, ymin, ymax;
  33.  
  34. extern long uiinited;    /* this is declared in pulldown.c */
  35.  
  36. long owid, newwid;
  37.  
  38. void createdialogarea()
  39. {
  40.     long screenx, screeny;
  41.     
  42.     screenx = getgdesc(GD_XPMAX);
  43.     screeny = getgdesc(GD_YPMAX);
  44.     xmin = xsize/2 - 300 + xorg;
  45.     ymin = ysize/2 - 55 + yorg;
  46.     if (xmin < 0) xmin = 0;
  47.     if (xmin + 600 >= screenx) xmin = screenx - 601;
  48.     if (ymin < 0) ymin = 0;
  49.     if (ymin + 110 >= screeny) ymin = screeny - 111;
  50.     xmax = xmin + 600;
  51.     ymax = ymin + 110;
  52.     prefposition(xmin, xmax, ymin, ymax);
  53.     noborder();
  54.     owid = winget();
  55.     newwid = winopen("dialog");
  56.     winset(newwid);
  57.     pushviewport();
  58.     savemat();
  59.     viewport(0, (short)(xmax-xmin), 0, (short)(ymax-ymin));
  60.     ortho2(-0.5, xmax-xmin+0.5, -0.5, ymax-ymin+0.5);
  61. }
  62.  
  63. void closedialogarea()
  64. {
  65.     unlocateall();
  66.     popviewport();
  67.     restoremat();
  68.     winclose(newwid);
  69. }
  70.  
  71. static void drawbackground()
  72. {
  73.     uiWhite(); rectfi(0, 0, xmax-xmin, ymax-ymin);
  74.     setpattern(P_UISHADOW);
  75.     uiVyLtGray(); rectfi(0, 0, xmax-xmin, ymax-ymin);
  76.     setpattern(0);
  77.     uiBlack();
  78. }
  79.  
  80. static void drawconfirmmessage(char *s)
  81. {
  82.     long cheight;
  83.     drawbackground();
  84.     recti(0, 0, 600, 110);
  85.     recti(3, 3, 597, 107);
  86.     recti(4, 4, 596, 106);
  87.     cheight = 80;
  88.     while (*s) {
  89.         char *sptr = s;
  90.     cmov2i(20, cheight); cheight -= 18;
  91.     while (*sptr && *sptr != '\n') sptr++;
  92.     if (*sptr)  {
  93.         *sptr = 0; charstr(s); *sptr = '\n'; s = sptr+1;
  94.     } else {
  95.         charstr(s);
  96.         s = sptr;
  97.     }
  98.     }
  99.     if (ybut) drawbut(ybut);
  100.     if (nbut) drawbut(nbut);
  101.     if (cbut) drawbut(cbut);
  102.     swapbuffers();
  103. }
  104.  
  105. static void makeconfirmbuts(char *b1, char *b2,  char *b3)
  106. {
  107.     createdialogarea();
  108.     if (ybut) freebut(ybut); ybut = 0;
  109.     if (nbut) freebut(nbut); nbut = 0;
  110.     if (cbut) freebut(cbut); cbut = 0;
  111.     if (b1) {
  112.         ybut = newbut(100, 15, 170, 45);
  113.     loadbut(ybut, b1);
  114.     }
  115.     if (b2) {
  116.         nbut = newbut(200, 15, 270, 45);
  117.     loadbut(nbut, b2);
  118.     }
  119.     if (b3) {
  120.         cbut = newbut(300, 15, 370, 45);
  121.     loadbut(cbut, b3);
  122.     }
  123. }
  124.  
  125. long message(char *str, char *b1, char *b2,  char *b3)
  126. {
  127.     short val;
  128.     long dev, mx, my;
  129.     static inited = 0;
  130.  
  131.     if (!uiinited) {
  132.         uiinited = 1;
  133.     initui();
  134.     }
  135.     if (inited == 0) {
  136.         inited = 1;
  137.         initbut();
  138.     }
  139.     makeconfirmbuts(b1, b2, b3);
  140.     drawconfirmmessage(str);
  141.     if (ybut == 0) {
  142.     (void)sleep(2);
  143.     closedialogarea();
  144.     return 0;
  145.     }
  146.     while (1) {
  147.     dev = qread(&val);
  148.     switch (dev) {
  149.         case 0:
  150.             break;
  151.         case MOUSEX:
  152.         case MOUSEY:
  153.         mx = getvaluator(MOUSEX) - xmin;
  154.         my = getvaluator(MOUSEY) - ymin;
  155.         if (ybut) locatebut(ybut, mx, my);
  156.         if (nbut) locatebut(nbut, mx, my);
  157.         if (cbut) locatebut(cbut, mx, my);
  158.         break;
  159.         case LEFTMOUSE:
  160.         if (val == 0) break;
  161.         mx = getvaluator(MOUSEX)  - xmin;
  162.         my = getvaluator(MOUSEY)  - ymin;
  163.         if (ybut && inbut(ybut, mx, my))
  164.             if (pressbut(ybut, mx, my)) {
  165.                 closedialogarea();
  166.                 return 1;
  167.             }
  168.         if (nbut && inbut(nbut, mx, my))
  169.             if (pressbut(nbut, mx, my)) {
  170.                 closedialogarea();
  171.                 return 2;
  172.             }
  173.         if (cbut && inbut(cbut, mx, my))
  174.             if (pressbut(cbut, mx, my)) {
  175.                 closedialogarea();
  176.                 return 3;
  177.             }
  178.         break;
  179.         case REDRAW:
  180.             winpop();
  181.         drawconfirmmessage(str);
  182.         break;
  183.         case WINQUIT:
  184.         case WINSHUT:
  185.         closedialogarea();
  186.         return 0;
  187.         default:
  188.             if (dev == MOUSEX || dev == MOUSEY) break;
  189.         drawconfirmmessage(str);
  190.         break;
  191.     }
  192.     }
  193. }
  194.  
  195.